package com.hezhiqin.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hezhiqin.mvcframework.annotation.HZQAutowired;
import com.hezhiqin.mvcframework.annotation.HZQController;
import com.hezhiqin.mvcframework.annotation.HZQRequestMapping;
import com.hezhiqin.mvcframework.annotation.HZQRequestParam;
import com.hezhiqin.service.IDemoService;

@HZQController
@HZQRequestMapping("/demo")
public class DemoAction {
	
	@HZQAutowired private IDemoService demoService;
	
	@HZQRequestMapping("/query")
	public void query(HttpServletRequest req, HttpServletResponse resp,
			@HZQRequestParam("name") String name) {
		System.out.println("demoService"+demoService);
		String result = demoService.get(name);
		try {
			resp.getWriter().write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	@HZQRequestMapping("/add")
	public void add(HttpServletRequest req, HttpServletResponse resp,
			@HZQRequestParam("a") Integer a,@HZQRequestParam("b") Integer b) {
		
		try {
			resp.getWriter().write(a + "+" + b + "=" + (a + b));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	
	@HZQRequestMapping("/remove")
	public void remove(HttpServletRequest req, HttpServletResponse resp,
			@HZQRequestParam("id") Integer id) {
		
		try {
			resp.getWriter().write(id);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}


}
